package 栈;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashSet;

/**
 * @author tmh
 * @date 2024/12/5 22:28
 * @description
 */
public class T20有效的括号 {
    public boolean isValid(String s) {
        Deque<Character> deque = new ArrayDeque<>();
        for (char c : s.toCharArray()) {
            if (c == '('){
                deque.push(')');
            } else if (c == '{') {
                deque.push('}');
            } else if (c == '[') {
                deque.push(']');
            }else if (deque.isEmpty()||deque.peek()!=c){
                return false;
            }else {
                deque.pop();
            }
        }
        return true;
    }
}
